{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="role" id="role" lay-search="">
                                <option  value="">不限类型</option>
                                <option  value="1">图文</option>
                                <option  value="2">视频</option>
                                <option  value="3">纯文</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户名/帖子内容"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <script type="text/html" id="titleTpl">
                        {{# if(d.post_type == 1){ }}
                        图文
                        {{# }else if(d.post_type == 2){ }}
                        视频
                        {{# }else{ }}
                        纯文
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.post_state == 1){ }}
                        正常
                        {{# }else if(d.post_state == 2){ }}
                        审核不通过
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.post_check == 1){ }}
                        <a href="javascript:;" onclick="check('{{d.post_id}}')" class="btn btn-primary btn-xs m-r-xs" >审核</a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.post_id}}','{:url('postDel')}')" class="btn btn-danger btn-xs m-r-xs">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("post/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'post_type', width: '', title: '帖子类型', align: 'center', templet: '#titleTpl'}
                , {field: 'post_content', width: '', title: '内容', align: 'center'}
                , {field: 'user_username', width: '', title: '用户名', align: 'center'}
                , {field: 'post_comment', width: '', title: '评论数', align: 'center'}
                , {field: 'post_praise', width: '', title: '点赞数', align: 'center'}
                , {field: 'post_give', width: '', title: '打赏积分数', align: 'center'}
                , {field: 'post_share', width: '', title: '分享数', align: 'center'}
                , {field: 'post_add_time', width: '', title: '发布时间', align: 'center'}
                , {field: 'post_state', width: 100, title: '状态', align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
    });

    function check(p_id) {
        layer.confirm('审核是否通过吗?', {
            icon: 3,
            title:'提示',
            btn: ['通过', '驳回'],
            btn2:function(index){
                send(p_id,2);
                layer.close(index);
            }}, function(index){
                send(p_id,1);
                layer.close(index);
        });
    }
    function send(p_id,type){
        $.ajax({
            url: "{:url('doCheck')}",
            type: "post",
            dataType: "json",
            data: {p_id:p_id,type:type},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>